package com.ham.mud.characters.player;

import com.ham.mud.Colors;
import com.ham.mud.ServerConnection;
import com.ham.mud.characters.MudCharacter;
import com.ham.mud.quests.Quest;
import com.sun.xml.internal.ws.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hlucas on Jun 16, 2011 at 1:40:28 PM
 */
public class Player extends MudCharacter {
    boolean colorEnabled = false;
    boolean asciiEnabled = true;

    Quest quest;

    String name;
    String zone;
    String password;

    int atX;
    int atY;

    int gold;
    int questPoints;

    public Player(String name, String password, String zone, int atX, int atY) {
        super();
        this.name = StringUtils.capitalize(name);
        this.password = password;
        this.zone = zone;
        this.atX = atX;
        this.atY = atY;         
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = StringUtils.capitalize(name);
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getAtX() {
        return atX;
    }

    public void setAtX(int atX) {
        this.atX = atX;
    }

    public int getAtY() {
        return atY;
    }

    public void setAtY(int atY) {
        this.atY = atY;
    }

    public boolean isColorEnabled() {
        return colorEnabled;
    }

    public void setColorEnabled(boolean color) {
        this.colorEnabled = color;
    }

    public boolean isAsciiEnabled() {
        return asciiEnabled;
    }

    public void setAsciiEnabled(boolean asciiEnabled) {
        this.asciiEnabled = asciiEnabled;
    }

    public String getZone() {
        return zone;
    }

    public void setZone(String zone) {
        this.zone = zone;
    }

    public String getShortDescription() {
        return getName() + " stands here.";
    }

    public String getLongDescription() {
        return getName() + " looks unclean."; //todo:implement;
    }

    public String[] getTargetingKeys() {
        return new String[]{getName().toLowerCase()};
    }

    public int getGold() {
        return gold;
    }

    public void setGold(int gold) {
        this.gold = gold;
    }

    public void decrementGold(int price) {
        gold -= price;
    }
    
    public void incrementGold(int price) {
        gold += price;
    }

    public int getQuestPoints() {
        return questPoints;
    }

    public void setQuestPoints(int questPoints) {
        this.questPoints = questPoints;
    }

    public void incrementQuestPoints(int by) {
        this.questPoints += by;
    }

    public void decrementQuestPoints(int by) {
        this.questPoints -= by;
    }

    public Quest getQuest() {
        return quest;
    }

    public void setQuest(Quest quest) {
        this.quest = quest;
    }

    public void regen(ServerConnection connection) {

        boolean health = vitals.regenHealth(getStrengthModifier());
        boolean mana = vitals.regenMana(getIntelligenceModifier());
        boolean move = vitals.regenMove(getDexterityModifier());
        boolean didRegen = health || mana || move;

        if(didRegen) {
            String regenString = getRegenString(health, mana, move);

            if(regenString != null) {
                connection.printSolo(Colors.NEW_LINE + regenString);
            }
        }
    }

    private String getRegenString(boolean health, boolean mana, boolean move) {
        int randInt = rand.nextInt(10);

        List<String> returnMessages = new ArrayList<String>();

        if(health) {
            returnMessages.add(getHealthRegenString(randInt));
        }

        if(mana) {
            returnMessages.add(getManaRegenString(randInt));
        }

        if(move) {
            returnMessages.add(getMoveRegenString(randInt));
        }

        return returnMessages.get(rand.nextInt(returnMessages.size()));
    }

    private String getHealthRegenString(int randInt) {
        switch(randInt) {
            case 0:
                return "It doesn't hurt as much to breath.";
            case 1:
                return "Your wounds itch.";
            case 2:
                return "You can feel your wounds healing.";
            case 3:
                return "A scab forms over one of your wounds.";
            case 4:
                return "A scab turns into a small scar.";
            case 5:
                return "You feel healthier.";
            case 6:
                return "Your wounds feel better.";
            case 7:
                return "You don't hurt as badly.";
            case 8:
                return "Your bruises clear up a bit.";
            case 9:
                return "You feel less sore.";
            default:
                return null;
        }
    }

    private String getManaRegenString(int randInt) {
        switch(randInt) {
            case 0:
                return "You don't feel so weak.";
            case 1:
                return "You feel the essence flowing in your veins.";
            case 2:
                return "Your essence flows.";
            case 3:
                return "Your essence grows.";
            case 4:
                return "Your essence increases.";
            case 5:
                return "You feel more magical.";
            case 6:
                return "You feel more able to cast spells.";
            case 7:
                return "You feel more powerful.";
            case 8:
                return "You breath deeply, taking in the essence of nature.";
            case 9:
                return "You feel more connected to nature.";
            default:
                return null;
        }
    }

    private String getMoveRegenString(int randInt) {
        switch(randInt) {
            case 0:
                return "You don't feel so tired.";
            case 1:
                return "Your legs are less sore.";
            case 2:
                return "You catch your breath.";
            case 3:
                return "You feel ready to carry on.";
            case 4:
                return "Your pulse slows down.";
            case 5:
                return "You feel more rested.";
            case 6:
                return "A breeze cools your brow.";
            case 7:
                return "You breath deeply, feeling rejuvenated.";
            case 8:
                return "Your breathing slows.";
            case 9:
                return "You feel less tired.";
            default:
                return null;
        }
    }
}
